package tr.edu.ege.kipler.syntax.concept;

import tr.edu.ege.kipler.syntax.ModalOperator;

/**
 * 
 * @author İnanç Seylan
 *
 */
public class ModalConcept extends Concept {
	private ModalOperator operator;

	private Concept concept;

	public ModalConcept() {

	}

	public ModalConcept(ModalOperator operator, Concept concept) {
		setOperator(operator);
		setConcept(concept);
	}

	public Concept getConcept() {
		return concept;
	}

	public void setConcept(Concept concept) {
		this.concept = concept;
	}

	public ModalOperator getOperator() {
		return operator;
	}

	public void setOperator(ModalOperator operator) {
		this.operator = operator;
	}

	public Concept toggleNegated() {
		setOperator(getOperator().getDual());
		setConcept(getConcept().toggleNegated());
		return this;
	}

	public boolean isNegated() {
		return false;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj != null && (obj.getClass().equals(this.getClass()))) {
			ModalConcept other = (ModalConcept) obj;
			return (this.getOperator().equals(other.getOperator()) && this
					.getConcept().equals(other.getConcept()));
		}
		return false;
	}

	/**
	 * This must be overridden when equals is overridden.
	 * 
	 * @return hash code of this formula.
	 */
	@Override
	public int hashCode() {
		return 17 * 37 + super.hashCode() + getOperator().hashCode()
				+ getConcept().hashCode();
	}

	/**
	 * @see tr.edu.ege.seagent.alcbi.syntax.Formula#copy()
	 */
	public ModalConcept copy() {
		ModalConcept md = new ModalConcept();
		md.setOperator(getOperator().copy());
		md.setConcept(getConcept().copy());
		return md;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(getOperator());
		buffer.append("(\"");
		// buffer.append(getAgent());
		buffer.append("\", ");
		buffer.append(getConcept());
		buffer.append(")");
		// ne need for negation check
		return buffer.toString();
	}

	public void accept(ConceptVisitor v) {
		v.visitModalConcept(this);
	}

}
